package by.dkusch.aircompany.services;

import java.util.List;

import javax.persistence.metamodel.SingularAttribute;

import org.springframework.transaction.annotation.Transactional;

import by.dkusch.aircompany.model.filter.base.FilterEntity;
import by.dkusch.aircompany.model.tables.base.BaseEntity;

public interface AbstractService<ID, Entity extends BaseEntity<ID>> {

	@Transactional
	Entity get(ID id);

	@Transactional
	void saveOrUpdate(Entity entity);

	@Transactional
	void delete(Entity entity);

	@Transactional
	void deleteAll();

	@Transactional
	void changeArchiveFL(boolean arcFL, Entity ent);

	@Transactional
	void saveList(List<Entity> records);

	boolean checkUniqueByFieldRestriction(final SingularAttribute<? super Entity, ?> attribute, final Object value, final ID id);

	boolean checkUniqueByFieldRestrictionAnyCase(final SingularAttribute<? super Entity, String> attribute, final String value, final ID id);

	boolean checkCanRemoveRecord(Entity entity);

	Long getCount();

	Long getCountWithFilter(FilterEntity<ID, ? super Entity> filter);

	List<Entity> getAll();

	List<Entity> getAllByFieldRestriction(final SingularAttribute<? super Entity, ?> attribute, final Object value);

	List<Entity> getAllByFieldRestrictionAnyCase(final SingularAttribute<? super Entity, String> attribute, final String value);

	List<Entity> getItemsWithOrder(SingularAttribute<? super Entity, ?> attr, boolean ascending, int startRecord, int pageSize);
	
	List<Entity> getItemsFilteredWithOrder(SingularAttribute<? super Entity, ?> attr, boolean ascending, int startRecord, int pageSize, FilterEntity<ID, ? super Entity> filter);

}
